﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class admin_module_article : System.Web.UI.UserControl
{
    Article_BU ar_BU = new Article_BU();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            getArticle();
        }
    }

    public void getArticle()
    {
        DataTable dt = ar_BU.Get_All_Article_BU();
        DataTable list_article = new DataTable();
        list_article.Columns.Add("id");
        list_article.Columns.Add("name_category");
        list_article.Columns.Add("name_topic");
        list_article.Columns.Add("name_article");
        list_article.Columns.Add("name_author");
        list_article.Columns.Add("add_date");
        list_article.Columns.Add("href");
        DataRow dr;
        foreach (DataRow r in dt.Rows)
        {
            dr = list_article.NewRow();
            dr["id"] = r["article_id"];
            dr["name_category"] = r["CategoryDes_Name"];
            dr["name_topic"] = r["topic_name"];
            dr["name_article"] = r["article_name"];
            dr["name_author"] = r["author"];
            dr["add_date"] = r["date_added"];
            dr["href"] = "~//admin//default.aspx?action=form_article&path=" + Convert.ToInt32(r["article_id"]);
            list_article.Rows.Add(dr);
        }

        dlArticle.DataSource = list_article;
        dlArticle.DataBind();
        if (list_article.Rows.Count == 0)
        {
            text_empty.Visible = true;
        }
    }
    protected void dlArticle_DeleteCommand(object source, DataListCommandEventArgs e)
    {
        int id = Convert.ToInt32(dlArticle.DataKeys[e.Item.ItemIndex]);
        int result = ar_BU.Delete_Article_BU(id);
        getArticle();
    }
}